{% regroup receptions|dictsort:"level" by level as grouped %}
{% for group in grouped %}
<h2 style="margin-top:30px;">{{ group.grouper }} <span>{{ str.application_specialities_desc }}</span></h2>
<div class="table">
    {% for reception in group.list|dictsort:"displayname" %}
    <div class="table_row" alt="{{ q.key }}">
        <div class="table_cell" style="white-space:nowrap;">
            {% ifequal post_url "/reception" %}
                <a href="/reception/{{ reception.key.id }}">{{ reception.displayname }}</a>
            {% else %}
                {% if reception.url %}
                <a href="{{ reception.url }}" target="_blank">{{ reception.displayname }}</a>
                {% else %}
                {{ reception.displayname }}
                {% endif %}
            {% endifequal %}
        </div>
        <div class="table_cell" style="white-space:nowrap; text-align:right;">
            <span style="color: gray; font-size:11px; margin-right:30px;">{{ reception.end }}</span>
        </div>
        <div class="table_cell" style="white-space:nowrap; width:300px;">
            {% ifequal post_url "/reception" %}
            <select name="radio_{{ reception.key.id }}" class="grade" bubble="{{ reception.key }}" style="float:right;"{% if reception.grade_is_locked %} disabled{% endif %}>
                <option value=""></option>
                {% for gd in reception.gradedefinitions %}
                <option value="{{ gd.key }}" {% ifequal gd.key reception.grade_key %}selected {% endifequal %}>{{ gd.displayname }}</option>
                {% endfor %}
            </select>
            {% else %}
            <p class="field switch" style="vertical-align:top; padding:0px; float:right;">
                <input type="radio" id="radio1" class="autosave_reception" name="field" checked />
                <input type="radio" id="radio2" class="autosave_reception" name="field" />
                <label for="radio1" class="cb-enable{% if reception.selected %} selected{% endif %}" alt="{{ reception.key }}"><span>{{ str.application_apply }}</span></label>
                <label for="radio2" class="cb-disable{% if reception.selected %}{% else %} selected{% endif %}" alt="{{ reception.key }}"><span>{{ str.application_dont_apply }}</span></label>
            </p>
            {% endifequal %}
        </div>
    </div>
    {% endfor %}
</div>
{% endfor %}

{% ifequal post_url "/reception" %}
<script>
    $(document).ready( function(){

        $(".grade").change(function(){
            var grade = $(this);
            $.post('/reception/rate', { person: '{{ person.key }}', bubble: grade.attr('bubble'), grade: grade.val() }, function(json) {

            }, 'json');

        });

    });
</script>
{% else %}
<script>
    $(document).ready( function(){
        $(".cb-enable").click(function(){
            var select = $(this);
            var parent = select.parents('.switch');
            $('.cb-disable',parent).removeClass('selected');
            select.addClass('selected');
            $('.checkbox',parent).attr('checked', true);

            autoSave(null, '{{ post_url }}', {
                key: select.attr('alt'),
                field: 'selected',
                value: 'true',
            });
        });

        $(".cb-disable").click(function(){
            var select = $(this);
            var parent = select.parents('.switch');
            $('.cb-enable',parent).removeClass('selected');
            select.addClass('selected');
            $('.checkbox',parent).attr('checked', false);

            autoSave(null, '{{ post_url }}', {
                key: select.attr('alt'),
                field: 'selected',
                value: 'false',
            });
        });
    });
</script>
{% endifequal %}